#include "stdafx.h"

#ifndef DLL_VECTOR2_CPP
#define DLL_VECTOR2_CPP

#include "Vector2.h"


const float FLOAT_EPSILON = .0001f;
const float SQV2_EPSILON = .0001f;
const float SQV2_EPSILON2= .0001f;

vector2::vector2(){};
vector2::~vector2(){};

inline const bool vector2::operator!=(vector2* v){return ((fabs(_x-v->_x)<FLOAT_EPSILON)&&(fabs(_y-v->_y)<FLOAT_EPSILON));};
inline const float vector2::operator*(vector2* v){return (_x*v->_y-_y*v->_x);};
inline vector2* vector2::operator+(vector2* v){return new vector2(_x+v->_x,_y+v->_y);};
inline vector2* vector2::operator-(vector2* v){return new vector2(_x-v->_x,_y-v->_y);};
inline const float vector2::norm(){return sqrtf(_x*_x+_y*_y);};
inline const float vector2::norm2(){return (_x*_x+_y*_y);};
inline const float vector2::dot(vector2* v2){return (_x*v2->_x+_y*v2->_y);};
inline const float vector2::cross(vector2* v2){return (_y*v2->_x-_x*v2->_y);};
inline void vector2::normalize(){float n=1.0f/sqrtf(_x*_x+_y*_y);_x*=n;_y*=n;};
inline void vector2::normalize_()
{
	float l = norm2();
	if (fabs(l-1.0f)>SQV2_EPSILON)
	{
		if (l>SQV2_EPSILON2){l=1.0f/sqrtf(l);_x*=l;_y*=l;};
	};
};
inline const float vector2::angle(vector2* v2){return atan2(v2->_y-_y,v2->_x-_x);};



BBAEXPcint NewVector2(const float x, const float y){return TobbObject(new vector2(x,y));};

BBAEXPcint Vector2Equal(vector2* v1, vector2* v2){return (v1!=v2);};

BBAEXPvoid SetVector2(vector2 *v, const float x, const float y){v->set(x,y);};
BBAEXPvoid SetVector2X(vector2 *v, const float x){v->setx(x);};
BBAEXPvoid SetVector2Y(vector2 *v, const float y){v->sety(y);};

BBAEXPcint DeleteVector2(vector2* v){delete v;return 0;};

BBAEXPcfloat Vector2X(vector2* v){return v->x();};
BBAEXPcfloat Vector2Y(vector2* v){return v->y();};

BBAEXPcfloat Vector2Mag(vector2* v){return v->norm();};
BBAEXPcfloat Vector2SquareMag(vector2* v){return v->norm2();};

BBAEXPcfloat Vector2Dot(vector2* v1, vector2* v2){return v1->dot(v2);};
//BBAEXPcfloat Vector2Cross(vector2& v1, vector2& v2){return (v1*v2);};
BBAEXPcfloat Vector2Cross(vector2* v1, vector2* v2){return v1->cross(v2);};

BBAEXPvoid  MagVector2(vector2* v){v->normalize();};
BBAEXPcfloat Vector2Angle(vector2* v1,vector2* v2){return v1->angle(v2);};

#endif //DLL_VECTOR2_CPP